/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.cmc.service.merchant.service.persistence;

import com.cmc.service.merchant.NoSuchMerchantEntryException;
import com.cmc.service.merchant.model.MerchantEntry;
import com.cmc.service.merchant.model.impl.MerchantEntryImpl;
import com.cmc.service.merchant.model.impl.MerchantEntryModelImpl;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ContactPersistence;
import com.liferay.portal.service.persistence.GroupPersistence;
import com.liferay.portal.service.persistence.OrganizationPersistence;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the merchant entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author ntcuong1
 * @see MerchantEntryPersistence
 * @see MerchantEntryUtil
 * @generated
 */
public class MerchantEntryPersistenceImpl extends BasePersistenceImpl<MerchantEntry>
	implements MerchantEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link MerchantEntryUtil} to access the merchant entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = MerchantEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANY = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByCompany",
			new String[] {
				Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANY =
		new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByCompany", new String[] { Long.class.getName() },
			MerchantEntryModelImpl.COMPANYID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_COMPANY = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompany",
			new String[] { Long.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_CODE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByCode",
			new String[] { String.class.getName() },
			MerchantEntryModelImpl.CODE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_CODE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCode",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_PARENT = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByParent",
			new String[] { Long.class.getName() },
			MerchantEntryModelImpl.PARENTID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_PARENT = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByParent",
			new String[] { Long.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByType",
			new String[] {
				String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByType", new String[] { String.class.getName() },
			MerchantEntryModelImpl.TYPE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE =
		new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByParentAndMerchantType",
			new String[] {
				Long.class.getName(), String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE =
		new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByParentAndMerchantType",
			new String[] { Long.class.getName(), String.class.getName() },
			MerchantEntryModelImpl.PARENTID_COLUMN_BITMASK |
			MerchantEntryModelImpl.TYPE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_PARENTANDMERCHANTTYPE = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByParentAndMerchantType",
			new String[] { Long.class.getName(), String.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED,
			MerchantEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the merchant entry in the entity cache if it is enabled.
	 *
	 * @param merchantEntry the merchant entry
	 */
	public void cacheResult(MerchantEntry merchantEntry) {
		EntityCacheUtil.putResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryImpl.class, merchantEntry.getPrimaryKey(),
			merchantEntry);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
			new Object[] { merchantEntry.getCode() }, merchantEntry);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PARENT,
			new Object[] { Long.valueOf(merchantEntry.getParentId()) },
			merchantEntry);

		merchantEntry.resetOriginalValues();
	}

	/**
	 * Caches the merchant entries in the entity cache if it is enabled.
	 *
	 * @param merchantEntries the merchant entries
	 */
	public void cacheResult(List<MerchantEntry> merchantEntries) {
		for (MerchantEntry merchantEntry : merchantEntries) {
			if (EntityCacheUtil.getResult(
						MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
						MerchantEntryImpl.class, merchantEntry.getPrimaryKey()) == null) {
				cacheResult(merchantEntry);
			}
			else {
				merchantEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all merchant entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(MerchantEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(MerchantEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the merchant entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(MerchantEntry merchantEntry) {
		EntityCacheUtil.removeResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryImpl.class, merchantEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(merchantEntry);
	}

	@Override
	public void clearCache(List<MerchantEntry> merchantEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (MerchantEntry merchantEntry : merchantEntries) {
			EntityCacheUtil.removeResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
				MerchantEntryImpl.class, merchantEntry.getPrimaryKey());

			clearUniqueFindersCache(merchantEntry);
		}
	}

	protected void clearUniqueFindersCache(MerchantEntry merchantEntry) {
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE,
			new Object[] { merchantEntry.getCode() });

		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PARENT,
			new Object[] { Long.valueOf(merchantEntry.getParentId()) });
	}

	/**
	 * Creates a new merchant entry with the primary key. Does not add the merchant entry to the database.
	 *
	 * @param merchantId the primary key for the new merchant entry
	 * @return the new merchant entry
	 */
	public MerchantEntry create(long merchantId) {
		MerchantEntry merchantEntry = new MerchantEntryImpl();

		merchantEntry.setNew(true);
		merchantEntry.setPrimaryKey(merchantId);

		return merchantEntry;
	}

	/**
	 * Removes the merchant entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param merchantId the primary key of the merchant entry
	 * @return the merchant entry that was removed
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry remove(long merchantId)
		throws NoSuchMerchantEntryException, SystemException {
		return remove(Long.valueOf(merchantId));
	}

	/**
	 * Removes the merchant entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the merchant entry
	 * @return the merchant entry that was removed
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public MerchantEntry remove(Serializable primaryKey)
		throws NoSuchMerchantEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			MerchantEntry merchantEntry = (MerchantEntry)session.get(MerchantEntryImpl.class,
					primaryKey);

			if (merchantEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchMerchantEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(merchantEntry);
		}
		catch (NoSuchMerchantEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected MerchantEntry removeImpl(MerchantEntry merchantEntry)
		throws SystemException {
		merchantEntry = toUnwrappedModel(merchantEntry);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, merchantEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(merchantEntry);

		return merchantEntry;
	}

	@Override
	public MerchantEntry updateImpl(
		com.cmc.service.merchant.model.MerchantEntry merchantEntry,
		boolean merge) throws SystemException {
		merchantEntry = toUnwrappedModel(merchantEntry);

		boolean isNew = merchantEntry.isNew();

		MerchantEntryModelImpl merchantEntryModelImpl = (MerchantEntryModelImpl)merchantEntry;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, merchantEntry, merge);

			merchantEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !MerchantEntryModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((merchantEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANY.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(merchantEntryModelImpl.getOriginalCompanyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANY, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANY,
					args);

				args = new Object[] {
						Long.valueOf(merchantEntryModelImpl.getCompanyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANY, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANY,
					args);
			}

			if ((merchantEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						merchantEntryModelImpl.getOriginalType()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
					args);

				args = new Object[] { merchantEntryModelImpl.getType() };

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
					args);
			}

			if ((merchantEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(merchantEntryModelImpl.getOriginalParentId()),
						
						merchantEntryModelImpl.getOriginalType()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTANDMERCHANTTYPE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE,
					args);

				args = new Object[] {
						Long.valueOf(merchantEntryModelImpl.getParentId()),
						
						merchantEntryModelImpl.getType()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTANDMERCHANTTYPE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE,
					args);
			}
		}

		EntityCacheUtil.putResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
			MerchantEntryImpl.class, merchantEntry.getPrimaryKey(),
			merchantEntry);

		if (isNew) {
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
				new Object[] { merchantEntry.getCode() }, merchantEntry);

			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PARENT,
				new Object[] { Long.valueOf(merchantEntry.getParentId()) },
				merchantEntry);
		}
		else {
			if ((merchantEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_CODE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						merchantEntryModelImpl.getOriginalCode()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODE, args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE, args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
					new Object[] { merchantEntry.getCode() }, merchantEntry);
			}

			if ((merchantEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_PARENT.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(merchantEntryModelImpl.getOriginalParentId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENT, args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PARENT, args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PARENT,
					new Object[] { Long.valueOf(merchantEntry.getParentId()) },
					merchantEntry);
			}
		}

		return merchantEntry;
	}

	protected MerchantEntry toUnwrappedModel(MerchantEntry merchantEntry) {
		if (merchantEntry instanceof MerchantEntryImpl) {
			return merchantEntry;
		}

		MerchantEntryImpl merchantEntryImpl = new MerchantEntryImpl();

		merchantEntryImpl.setNew(merchantEntry.isNew());
		merchantEntryImpl.setPrimaryKey(merchantEntry.getPrimaryKey());

		merchantEntryImpl.setMerchantId(merchantEntry.getMerchantId());
		merchantEntryImpl.setCompanyId(merchantEntry.getCompanyId());
		merchantEntryImpl.setCreatorUserId(merchantEntry.getCreatorUserId());
		merchantEntryImpl.setCreateDate(merchantEntry.getCreateDate());
		merchantEntryImpl.setModifiedDate(merchantEntry.getModifiedDate());
		merchantEntryImpl.setType(merchantEntry.getType());
		merchantEntryImpl.setCode(merchantEntry.getCode());
		merchantEntryImpl.setTitle(merchantEntry.getTitle());
		merchantEntryImpl.setDescription(merchantEntry.getDescription());
		merchantEntryImpl.setOrganization(merchantEntry.isOrganization());
		merchantEntryImpl.setOrganizationId(merchantEntry.getOrganizationId());
		merchantEntryImpl.setOrganizationType(merchantEntry.getOrganizationType());
		merchantEntryImpl.setOrganizationStatus(merchantEntry.getOrganizationStatus());
		merchantEntryImpl.setSites(merchantEntry.isSites());
		merchantEntryImpl.setRecursable(merchantEntry.isRecursable());
		merchantEntryImpl.setCountryId(merchantEntry.getCountryId());
		merchantEntryImpl.setRegionId(merchantEntry.getRegionId());
		merchantEntryImpl.setLongitude(merchantEntry.getLongitude());
		merchantEntryImpl.setLatitude(merchantEntry.getLatitude());
		merchantEntryImpl.setParentId(merchantEntry.getParentId());

		return merchantEntryImpl;
	}

	/**
	 * Returns the merchant entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the merchant entry
	 * @return the merchant entry
	 * @throws com.liferay.portal.NoSuchModelException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public MerchantEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the merchant entry with the primary key or throws a {@link com.cmc.service.merchant.NoSuchMerchantEntryException} if it could not be found.
	 *
	 * @param merchantId the primary key of the merchant entry
	 * @return the merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByPrimaryKey(long merchantId)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByPrimaryKey(merchantId);

		if (merchantEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + merchantId);
			}

			throw new NoSuchMerchantEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				merchantId);
		}

		return merchantEntry;
	}

	/**
	 * Returns the merchant entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the merchant entry
	 * @return the merchant entry, or <code>null</code> if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public MerchantEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the merchant entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param merchantId the primary key of the merchant entry
	 * @return the merchant entry, or <code>null</code> if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByPrimaryKey(long merchantId)
		throws SystemException {
		MerchantEntry merchantEntry = (MerchantEntry)EntityCacheUtil.getResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
				MerchantEntryImpl.class, merchantId);

		if (merchantEntry == _nullMerchantEntry) {
			return null;
		}

		if (merchantEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				merchantEntry = (MerchantEntry)session.get(MerchantEntryImpl.class,
						Long.valueOf(merchantId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (merchantEntry != null) {
					cacheResult(merchantEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(MerchantEntryModelImpl.ENTITY_CACHE_ENABLED,
						MerchantEntryImpl.class, merchantId, _nullMerchantEntry);
				}

				closeSession(session);
			}
		}

		return merchantEntry;
	}

	/**
	 * Returns all the merchant entries where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @return the matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByCompany(long companyId)
		throws SystemException {
		return findByCompany(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
			null);
	}

	/**
	 * Returns a range of all the merchant entries where companyId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param companyId the company ID
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @return the range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByCompany(long companyId, int start, int end)
		throws SystemException {
		return findByCompany(companyId, start, end, null);
	}

	/**
	 * Returns an ordered range of all the merchant entries where companyId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param companyId the company ID
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByCompany(long companyId, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANY;
			finderArgs = new Object[] { companyId };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANY;
			finderArgs = new Object[] { companyId, start, end, orderByComparator };
		}

		List<MerchantEntry> list = (List<MerchantEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if ((list != null) && !list.isEmpty()) {
			for (MerchantEntry merchantEntry : list) {
				if ((companyId != merchantEntry.getCompanyId())) {
					list = null;

					break;
				}
			}
		}

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_COMPANY_COMPANYID_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(companyId);

				list = (List<MerchantEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first merchant entry in the ordered set where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByCompany_First(long companyId,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByCompany_First(companyId,
				orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(4);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("companyId=");
		msg.append(companyId);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the first merchant entry in the ordered set where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByCompany_First(long companyId,
		OrderByComparator orderByComparator) throws SystemException {
		List<MerchantEntry> list = findByCompany(companyId, 0, 1,
				orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the last merchant entry in the ordered set where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByCompany_Last(long companyId,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByCompany_Last(companyId,
				orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(4);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("companyId=");
		msg.append(companyId);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the last merchant entry in the ordered set where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByCompany_Last(long companyId,
		OrderByComparator orderByComparator) throws SystemException {
		int count = countByCompany(companyId);

		List<MerchantEntry> list = findByCompany(companyId, count - 1, count,
				orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the merchant entries before and after the current merchant entry in the ordered set where companyId = &#63;.
	 *
	 * @param merchantId the primary key of the current merchant entry
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry[] findByCompany_PrevAndNext(long merchantId,
		long companyId, OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = findByPrimaryKey(merchantId);

		Session session = null;

		try {
			session = openSession();

			MerchantEntry[] array = new MerchantEntryImpl[3];

			array[0] = getByCompany_PrevAndNext(session, merchantEntry,
					companyId, orderByComparator, true);

			array[1] = merchantEntry;

			array[2] = getByCompany_PrevAndNext(session, merchantEntry,
					companyId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected MerchantEntry getByCompany_PrevAndNext(Session session,
		MerchantEntry merchantEntry, long companyId,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

		query.append(_FINDER_COLUMN_COMPANY_COMPANYID_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(companyId);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(merchantEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<MerchantEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns the merchant entry where code = &#63; or throws a {@link com.cmc.service.merchant.NoSuchMerchantEntryException} if it could not be found.
	 *
	 * @param code the code
	 * @return the matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByCode(String code)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByCode(code);

		if (merchantEntry == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("code=");
			msg.append(code);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchMerchantEntryException(msg.toString());
		}

		return merchantEntry;
	}

	/**
	 * Returns the merchant entry where code = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param code the code
	 * @return the matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByCode(String code) throws SystemException {
		return fetchByCode(code, true);
	}

	/**
	 * Returns the merchant entry where code = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param code the code
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByCode(String code, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { code };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CODE,
					finderArgs, this);
		}

		if (result instanceof MerchantEntry) {
			MerchantEntry merchantEntry = (MerchantEntry)result;

			if (!Validator.equals(code, merchantEntry.getCode())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

			if (code == null) {
				query.append(_FINDER_COLUMN_CODE_CODE_1);
			}
			else {
				if (code.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_CODE_CODE_3);
				}
				else {
					query.append(_FINDER_COLUMN_CODE_CODE_2);
				}
			}

			query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (code != null) {
					qPos.add(code);
				}

				List<MerchantEntry> list = q.list();

				result = list;

				MerchantEntry merchantEntry = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
						finderArgs, list);
				}
				else {
					merchantEntry = list.get(0);

					cacheResult(merchantEntry);

					if ((merchantEntry.getCode() == null) ||
							!merchantEntry.getCode().equals(code)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
							finderArgs, merchantEntry);
					}
				}

				return merchantEntry;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (MerchantEntry)result;
			}
		}
	}

	/**
	 * Returns the merchant entry where parentId = &#63; or throws a {@link com.cmc.service.merchant.NoSuchMerchantEntryException} if it could not be found.
	 *
	 * @param parentId the parent ID
	 * @return the matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByParent(long parentId)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByParent(parentId);

		if (merchantEntry == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("parentId=");
			msg.append(parentId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchMerchantEntryException(msg.toString());
		}

		return merchantEntry;
	}

	/**
	 * Returns the merchant entry where parentId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param parentId the parent ID
	 * @return the matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByParent(long parentId) throws SystemException {
		return fetchByParent(parentId, true);
	}

	/**
	 * Returns the merchant entry where parentId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param parentId the parent ID
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByParent(long parentId, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { parentId };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_PARENT,
					finderArgs, this);
		}

		if (result instanceof MerchantEntry) {
			MerchantEntry merchantEntry = (MerchantEntry)result;

			if ((parentId != merchantEntry.getParentId())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_PARENT_PARENTID_2);

			query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(parentId);

				List<MerchantEntry> list = q.list();

				result = list;

				MerchantEntry merchantEntry = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PARENT,
						finderArgs, list);
				}
				else {
					merchantEntry = list.get(0);

					cacheResult(merchantEntry);

					if ((merchantEntry.getParentId() != parentId)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PARENT,
							finderArgs, merchantEntry);
					}
				}

				return merchantEntry;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PARENT,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (MerchantEntry)result;
			}
		}
	}

	/**
	 * Returns all the merchant entries where type = &#63;.
	 *
	 * @param type the type
	 * @return the matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByType(String type)
		throws SystemException {
		return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the merchant entries where type = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param type the type
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @return the range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByType(String type, int start, int end)
		throws SystemException {
		return findByType(type, start, end, null);
	}

	/**
	 * Returns an ordered range of all the merchant entries where type = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param type the type
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByType(String type, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
			finderArgs = new Object[] { type };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
			finderArgs = new Object[] { type, start, end, orderByComparator };
		}

		List<MerchantEntry> list = (List<MerchantEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if ((list != null) && !list.isEmpty()) {
			for (MerchantEntry merchantEntry : list) {
				if (!Validator.equals(type, merchantEntry.getType())) {
					list = null;

					break;
				}
			}
		}

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

			if (type == null) {
				query.append(_FINDER_COLUMN_TYPE_TYPE_1);
			}
			else {
				if (type.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_TYPE_TYPE_3);
				}
				else {
					query.append(_FINDER_COLUMN_TYPE_TYPE_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (type != null) {
					qPos.add(type);
				}

				list = (List<MerchantEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first merchant entry in the ordered set where type = &#63;.
	 *
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByType_First(String type,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByType_First(type, orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(4);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("type=");
		msg.append(type);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the first merchant entry in the ordered set where type = &#63;.
	 *
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByType_First(String type,
		OrderByComparator orderByComparator) throws SystemException {
		List<MerchantEntry> list = findByType(type, 0, 1, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the last merchant entry in the ordered set where type = &#63;.
	 *
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByType_Last(String type,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByType_Last(type, orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(4);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("type=");
		msg.append(type);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the last merchant entry in the ordered set where type = &#63;.
	 *
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByType_Last(String type,
		OrderByComparator orderByComparator) throws SystemException {
		int count = countByType(type);

		List<MerchantEntry> list = findByType(type, count - 1, count,
				orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the merchant entries before and after the current merchant entry in the ordered set where type = &#63;.
	 *
	 * @param merchantId the primary key of the current merchant entry
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry[] findByType_PrevAndNext(long merchantId, String type,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = findByPrimaryKey(merchantId);

		Session session = null;

		try {
			session = openSession();

			MerchantEntry[] array = new MerchantEntryImpl[3];

			array[0] = getByType_PrevAndNext(session, merchantEntry, type,
					orderByComparator, true);

			array[1] = merchantEntry;

			array[2] = getByType_PrevAndNext(session, merchantEntry, type,
					orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected MerchantEntry getByType_PrevAndNext(Session session,
		MerchantEntry merchantEntry, String type,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

		if (type == null) {
			query.append(_FINDER_COLUMN_TYPE_TYPE_1);
		}
		else {
			if (type.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_TYPE_TYPE_3);
			}
			else {
				query.append(_FINDER_COLUMN_TYPE_TYPE_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (type != null) {
			qPos.add(type);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(merchantEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<MerchantEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the merchant entries where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @return the matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByParentAndMerchantType(long parentId,
		String type) throws SystemException {
		return findByParentAndMerchantType(parentId, type, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the merchant entries where parentId = &#63; and type = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @return the range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByParentAndMerchantType(long parentId,
		String type, int start, int end) throws SystemException {
		return findByParentAndMerchantType(parentId, type, start, end, null);
	}

	/**
	 * Returns an ordered range of all the merchant entries where parentId = &#63; and type = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findByParentAndMerchantType(long parentId,
		String type, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE;
			finderArgs = new Object[] { parentId, type };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTANDMERCHANTTYPE;
			finderArgs = new Object[] {
					parentId, type,
					
					start, end, orderByComparator
				};
		}

		List<MerchantEntry> list = (List<MerchantEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if ((list != null) && !list.isEmpty()) {
			for (MerchantEntry merchantEntry : list) {
				if ((parentId != merchantEntry.getParentId()) ||
						!Validator.equals(type, merchantEntry.getType())) {
					list = null;

					break;
				}
			}
		}

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_PARENTID_2);

			if (type == null) {
				query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_1);
			}
			else {
				if (type.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_3);
				}
				else {
					query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(parentId);

				if (type != null) {
					qPos.add(type);
				}

				list = (List<MerchantEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first merchant entry in the ordered set where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByParentAndMerchantType_First(long parentId,
		String type, OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByParentAndMerchantType_First(parentId,
				type, orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(6);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("parentId=");
		msg.append(parentId);

		msg.append(", type=");
		msg.append(type);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the first merchant entry in the ordered set where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByParentAndMerchantType_First(long parentId,
		String type, OrderByComparator orderByComparator)
		throws SystemException {
		List<MerchantEntry> list = findByParentAndMerchantType(parentId, type,
				0, 1, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the last merchant entry in the ordered set where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry findByParentAndMerchantType_Last(long parentId,
		String type, OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = fetchByParentAndMerchantType_Last(parentId,
				type, orderByComparator);

		if (merchantEntry != null) {
			return merchantEntry;
		}

		StringBundler msg = new StringBundler(6);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("parentId=");
		msg.append(parentId);

		msg.append(", type=");
		msg.append(type);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchMerchantEntryException(msg.toString());
	}

	/**
	 * Returns the last merchant entry in the ordered set where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching merchant entry, or <code>null</code> if a matching merchant entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry fetchByParentAndMerchantType_Last(long parentId,
		String type, OrderByComparator orderByComparator)
		throws SystemException {
		int count = countByParentAndMerchantType(parentId, type);

		List<MerchantEntry> list = findByParentAndMerchantType(parentId, type,
				count - 1, count, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the merchant entries before and after the current merchant entry in the ordered set where parentId = &#63; and type = &#63;.
	 *
	 * @param merchantId the primary key of the current merchant entry
	 * @param parentId the parent ID
	 * @param type the type
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next merchant entry
	 * @throws com.cmc.service.merchant.NoSuchMerchantEntryException if a merchant entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry[] findByParentAndMerchantType_PrevAndNext(
		long merchantId, long parentId, String type,
		OrderByComparator orderByComparator)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = findByPrimaryKey(merchantId);

		Session session = null;

		try {
			session = openSession();

			MerchantEntry[] array = new MerchantEntryImpl[3];

			array[0] = getByParentAndMerchantType_PrevAndNext(session,
					merchantEntry, parentId, type, orderByComparator, true);

			array[1] = merchantEntry;

			array[2] = getByParentAndMerchantType_PrevAndNext(session,
					merchantEntry, parentId, type, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected MerchantEntry getByParentAndMerchantType_PrevAndNext(
		Session session, MerchantEntry merchantEntry, long parentId,
		String type, OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_MERCHANTENTRY_WHERE);

		query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_PARENTID_2);

		if (type == null) {
			query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_1);
		}
		else {
			if (type.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_3);
			}
			else {
				query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(MerchantEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(parentId);

		if (type != null) {
			qPos.add(type);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(merchantEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<MerchantEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the merchant entries.
	 *
	 * @return the merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the merchant entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @return the range of merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the merchant entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<MerchantEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<MerchantEntry> list = (List<MerchantEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_MERCHANTENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_MERCHANTENTRY.concat(MerchantEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<MerchantEntry>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<MerchantEntry>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the merchant entries where companyId = &#63; from the database.
	 *
	 * @param companyId the company ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByCompany(long companyId) throws SystemException {
		for (MerchantEntry merchantEntry : findByCompany(companyId)) {
			remove(merchantEntry);
		}
	}

	/**
	 * Removes the merchant entry where code = &#63; from the database.
	 *
	 * @param code the code
	 * @return the merchant entry that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry removeByCode(String code)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = findByCode(code);

		return remove(merchantEntry);
	}

	/**
	 * Removes the merchant entry where parentId = &#63; from the database.
	 *
	 * @param parentId the parent ID
	 * @return the merchant entry that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public MerchantEntry removeByParent(long parentId)
		throws NoSuchMerchantEntryException, SystemException {
		MerchantEntry merchantEntry = findByParent(parentId);

		return remove(merchantEntry);
	}

	/**
	 * Removes all the merchant entries where type = &#63; from the database.
	 *
	 * @param type the type
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByType(String type) throws SystemException {
		for (MerchantEntry merchantEntry : findByType(type)) {
			remove(merchantEntry);
		}
	}

	/**
	 * Removes all the merchant entries where parentId = &#63; and type = &#63; from the database.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByParentAndMerchantType(long parentId, String type)
		throws SystemException {
		for (MerchantEntry merchantEntry : findByParentAndMerchantType(
				parentId, type)) {
			remove(merchantEntry);
		}
	}

	/**
	 * Removes all the merchant entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (MerchantEntry merchantEntry : findAll()) {
			remove(merchantEntry);
		}
	}

	/**
	 * Returns the number of merchant entries where companyId = &#63;.
	 *
	 * @param companyId the company ID
	 * @return the number of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByCompany(long companyId) throws SystemException {
		Object[] finderArgs = new Object[] { companyId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANY,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_COMPANY_COMPANYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(companyId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANY,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of merchant entries where code = &#63;.
	 *
	 * @param code the code
	 * @return the number of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByCode(String code) throws SystemException {
		Object[] finderArgs = new Object[] { code };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_MERCHANTENTRY_WHERE);

			if (code == null) {
				query.append(_FINDER_COLUMN_CODE_CODE_1);
			}
			else {
				if (code.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_CODE_CODE_3);
				}
				else {
					query.append(_FINDER_COLUMN_CODE_CODE_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (code != null) {
					qPos.add(code);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of merchant entries where parentId = &#63;.
	 *
	 * @param parentId the parent ID
	 * @return the number of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByParent(long parentId) throws SystemException {
		Object[] finderArgs = new Object[] { parentId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PARENT,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_PARENT_PARENTID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(parentId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PARENT,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of merchant entries where type = &#63;.
	 *
	 * @param type the type
	 * @return the number of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByType(String type) throws SystemException {
		Object[] finderArgs = new Object[] { type };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_MERCHANTENTRY_WHERE);

			if (type == null) {
				query.append(_FINDER_COLUMN_TYPE_TYPE_1);
			}
			else {
				if (type.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_TYPE_TYPE_3);
				}
				else {
					query.append(_FINDER_COLUMN_TYPE_TYPE_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (type != null) {
					qPos.add(type);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of merchant entries where parentId = &#63; and type = &#63;.
	 *
	 * @param parentId the parent ID
	 * @param type the type
	 * @return the number of matching merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByParentAndMerchantType(long parentId, String type)
		throws SystemException {
		Object[] finderArgs = new Object[] { parentId, type };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PARENTANDMERCHANTTYPE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_MERCHANTENTRY_WHERE);

			query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_PARENTID_2);

			if (type == null) {
				query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_1);
			}
			else {
				if (type.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_3);
				}
				else {
					query.append(_FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(parentId);

				if (type != null) {
					qPos.add(type);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PARENTANDMERCHANTTYPE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of merchant entries.
	 *
	 * @return the number of merchant entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_MERCHANTENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the agent entries associated with the merchant entry.
	 *
	 * @param pk the primary key of the merchant entry
	 * @return the agent entries associated with the merchant entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.cmc.service.merchant.model.AgentEntry> getAgentEntries(
		long pk) throws SystemException {
		return getAgentEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the agent entries associated with the merchant entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the merchant entry
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @return the range of agent entries associated with the merchant entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.cmc.service.merchant.model.AgentEntry> getAgentEntries(
		long pk, int start, int end) throws SystemException {
		return getAgentEntries(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_AGENTENTRIES = new FinderPath(com.cmc.service.merchant.model.impl.AgentEntryModelImpl.ENTITY_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryModelImpl.FINDER_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryImpl.class,
			com.cmc.service.merchant.service.persistence.AgentEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getAgentEntries",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	static {
		FINDER_PATH_GET_AGENTENTRIES.setCacheKeyGeneratorCacheName(null);
	}

	/**
	 * Returns an ordered range of all the agent entries associated with the merchant entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the merchant entry
	 * @param start the lower bound of the range of merchant entries
	 * @param end the upper bound of the range of merchant entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of agent entries associated with the merchant entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.cmc.service.merchant.model.AgentEntry> getAgentEntries(
		long pk, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<com.cmc.service.merchant.model.AgentEntry> list = (List<com.cmc.service.merchant.model.AgentEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_AGENTENTRIES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETAGENTENTRIES.concat(ORDER_BY_CLAUSE)
											  .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETAGENTENTRIES.concat(com.cmc.service.merchant.model.impl.AgentEntryModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("CTI_AgentEntry",
					com.cmc.service.merchant.model.impl.AgentEntryImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<com.cmc.service.merchant.model.AgentEntry>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_AGENTENTRIES,
						finderArgs);
				}
				else {
					agentEntryPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_AGENTENTRIES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_AGENTENTRIES_SIZE = new FinderPath(com.cmc.service.merchant.model.impl.AgentEntryModelImpl.ENTITY_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryModelImpl.FINDER_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryImpl.class,
			com.cmc.service.merchant.service.persistence.AgentEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getAgentEntriesSize", new String[] { Long.class.getName() });

	static {
		FINDER_PATH_GET_AGENTENTRIES_SIZE.setCacheKeyGeneratorCacheName(null);
	}

	/**
	 * Returns the number of agent entries associated with the merchant entry.
	 *
	 * @param pk the primary key of the merchant entry
	 * @return the number of agent entries associated with the merchant entry
	 * @throws SystemException if a system exception occurred
	 */
	public int getAgentEntriesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_AGENTENTRIES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETAGENTENTRIESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_AGENTENTRIES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_AGENTENTRY = new FinderPath(com.cmc.service.merchant.model.impl.AgentEntryModelImpl.ENTITY_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryModelImpl.FINDER_CACHE_ENABLED,
			com.cmc.service.merchant.model.impl.AgentEntryImpl.class,
			com.cmc.service.merchant.service.persistence.AgentEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsAgentEntry",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the agent entry is associated with the merchant entry.
	 *
	 * @param pk the primary key of the merchant entry
	 * @param agentEntryPK the primary key of the agent entry
	 * @return <code>true</code> if the agent entry is associated with the merchant entry; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsAgentEntry(long pk, long agentEntryPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, agentEntryPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_AGENTENTRY,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsAgentEntry.contains(pk,
							agentEntryPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_AGENTENTRY,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the merchant entry has any agent entries associated with it.
	 *
	 * @param pk the primary key of the merchant entry to check for associations with agent entries
	 * @return <code>true</code> if the merchant entry has any agent entries associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsAgentEntries(long pk) throws SystemException {
		if (getAgentEntriesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Initializes the merchant entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.cmc.service.merchant.model.MerchantEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<MerchantEntry>> listenersList = new ArrayList<ModelListener<MerchantEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<MerchantEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsAgentEntry = new ContainsAgentEntry();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(MerchantEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = AgentEntryPersistence.class)
	protected AgentEntryPersistence agentEntryPersistence;
	@BeanReference(type = MerchantEntryPersistence.class)
	protected MerchantEntryPersistence merchantEntryPersistence;
	@BeanReference(type = ContactPersistence.class)
	protected ContactPersistence contactPersistence;
	@BeanReference(type = GroupPersistence.class)
	protected GroupPersistence groupPersistence;
	@BeanReference(type = OrganizationPersistence.class)
	protected OrganizationPersistence organizationPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected ContainsAgentEntry containsAgentEntry;

	protected class ContainsAgentEntry {
		protected ContainsAgentEntry() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSAGENTENTRY,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long merchantId, long agentId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(merchantId), new Long(agentId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	private static final String _SQL_SELECT_MERCHANTENTRY = "SELECT merchantEntry FROM MerchantEntry merchantEntry";
	private static final String _SQL_SELECT_MERCHANTENTRY_WHERE = "SELECT merchantEntry FROM MerchantEntry merchantEntry WHERE ";
	private static final String _SQL_COUNT_MERCHANTENTRY = "SELECT COUNT(merchantEntry) FROM MerchantEntry merchantEntry";
	private static final String _SQL_COUNT_MERCHANTENTRY_WHERE = "SELECT COUNT(merchantEntry) FROM MerchantEntry merchantEntry WHERE ";
	private static final String _SQL_GETAGENTENTRIES = "SELECT {CTI_AgentEntry.*} FROM CTI_AgentEntry INNER JOIN CTI_MerchantEntry ON (CTI_MerchantEntry.merchantId = CTI_AgentEntry.merchantId) WHERE (CTI_MerchantEntry.merchantId = ?)";
	private static final String _SQL_GETAGENTENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM CTI_AgentEntry WHERE merchantId = ?";
	private static final String _SQL_CONTAINSAGENTENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM CTI_AgentEntry WHERE merchantId = ? AND agentId = ?";
	private static final String _FINDER_COLUMN_COMPANY_COMPANYID_2 = "merchantEntry.companyId = ?";
	private static final String _FINDER_COLUMN_CODE_CODE_1 = "merchantEntry.code IS NULL";
	private static final String _FINDER_COLUMN_CODE_CODE_2 = "merchantEntry.code = ?";
	private static final String _FINDER_COLUMN_CODE_CODE_3 = "(merchantEntry.code IS NULL OR merchantEntry.code = ?)";
	private static final String _FINDER_COLUMN_PARENT_PARENTID_2 = "merchantEntry.parentId = ?";
	private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "merchantEntry.type IS NULL";
	private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "merchantEntry.type = ?";
	private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(merchantEntry.type IS NULL OR merchantEntry.type = ?)";
	private static final String _FINDER_COLUMN_PARENTANDMERCHANTTYPE_PARENTID_2 = "merchantEntry.parentId = ? AND ";
	private static final String _FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_1 = "merchantEntry.type IS NULL";
	private static final String _FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_2 = "merchantEntry.type = ?";
	private static final String _FINDER_COLUMN_PARENTANDMERCHANTTYPE_TYPE_3 = "(merchantEntry.type IS NULL OR merchantEntry.type = ?)";
	private static final String _ORDER_BY_ENTITY_ALIAS = "merchantEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MerchantEntry exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MerchantEntry exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(MerchantEntryPersistenceImpl.class);
	private static MerchantEntry _nullMerchantEntry = new MerchantEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<MerchantEntry> toCacheModel() {
				return _nullMerchantEntryCacheModel;
			}
		};

	private static CacheModel<MerchantEntry> _nullMerchantEntryCacheModel = new CacheModel<MerchantEntry>() {
			public MerchantEntry toEntityModel() {
				return _nullMerchantEntry;
			}
		};
}